//jQuery OpenID Plugin 1.1 Copyright 2009 Jarrett Vance http://jvance.com/pages/jQueryOpenIdPlugin.xhtml
$.fn.openid = function() {
  var $this = $(this);
  var $usr = $this.find('input[name=openid_username]');
  var $id = $this.find('input[name=openid_identifier]');
  var $front = $this.find('div:has(input[name=openid_username])>span:eq(0)');
  var $end = $this.find('div:has(input[name=openid_username])>span:eq(1)');
  var $usrfs = $this.find('fieldset:has(input[name=openid_username])');
  var $idfs = $this.find('fieldset:has(input[name=openid_identifier])');

  var submitusr = function() {
    if ($usr.val().length < 1) {
      $usr.focus();
      return false;
    }
    $id.val($front.text() + $usr.val() + $end.text());
    return true;
  };

  var submitid = function() {
    if ($id.val().length < 1) {
      $id.focus();
      return false;
    }
    return true;

  };
  var direct = function() {
    var $li = $(this);
    $li.parent().find('li').removeClass('highlight');
    $li.addClass('highlight');
    $usrfs.fadeOut();
    $idfs.fadeOut();

    $this.unbind('submit').submit(function() {
      $id.val($this.find("li.highlight span").text());
    });
    $this.submit();
    return false;
  };

  var openid = function() {
    var $li = $(this);
    $li.parent().find('li').removeClass('highlight');
    $li.addClass('highlight');
    $usrfs.hide();
    $idfs.show();
    $id.focus();
    $this.unbind('submit').submit(submitid);
    return false;
  };

  var username = function() {
    var $li = $(this);
    $li.parent().find('li').removeClass('highlight');
    $li.addClass('highlight');
    $idfs.hide();
    $usrfs.show();
    $this.find('label[for=openid_username] span').text($li.attr("title"));
    $front.text($li.find("span").text().split("username")[0]);
    $end.text("").text($li.find("span").text().split("username")[1]);
    $id.focus();
    $this.unbind('submit').submit(submitusr);
    return false;
  };

  $this.find('li.direct').click(direct);
  $this.find('li.openid').click(openid);
  $this.find('li.username').click(username);
  $id.keypress(function(e) {
    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
      return submitid();
    }
  });
  $usr.keypress(function(e) {
    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
      return submitusr();
    }
  });
  $this.find('li span').hide();
  $this.find('li').css('line-height', 0).css('cursor', 'pointer');
  $this.find('li:eq(0)').click();
  return this;
};

function del(b, a) {
    b = getSelectorId(b);
    $(b).fadeTo(500, 0.4, function() {
        if (confirm("Are you sure you want to delete this entry?")) {
            $.ajax({ type: "DELETE", data: "", url: a, complete: function(c) {
                if (c.status == 200) { $(b).fadeOut(function() { $(this).remove() }) } else {
                    alert("Failed to delete entry: " + c.responseText); 
    $(b).fadeTo(1000, 1) } } }) } else { $(b).fadeTo(500, 1) } })
} function approve(d, b, a) {
    d = getSelectorId(d); var c = $(a).text().toUpperCase() == "APPROVE";
    $(d).fadeTo(800, 0.3, function() {
        $.ajax({ type: "POST", data: "approved=" + c, url: b, complete: function(e) {
            if (e.status == 200) {
                if (!c) {
                    $(d).removeClass("commentApprove").addClass("commentNotApproved"); $(a).text("Approve")
                } else {
                $(d).removeClass("commentNotApproved").addClass("commentApprove"); $(a).text("Unapprove")
            }
            $(d).find("em.warning").remove()
        } else { alert("Failed to set approval: " + e.responseText) }
        $(d).fadeTo(2000, 1)
    } 
})
})
} function approveAll(c, b, a) {
$.ajax({ type: "POST", data: "", url: b, complete: function(d) {
    if (d.status == 200) {
        alert("Approved: " + d.responseText);
        $(a).remove(); $("#comments div.commentNotApproved").fadeTo(800, 0.3, function() {
            $('#comments button:contains("Approve")').remove();
            $("#comments em.warning").remove(); $("#comments div.commentNotApproved").toggleClass("commentNotApproved").addClass("commentApprove").fadeTo(2000, 1)
        })
    }
    else { alert("Failed to approve: " + d.responseText) } 
} 
})
}
function getSelectorId(a) { return "#" + a.toString().replace(/:/g, "\\:").replace(/\./g, "\\.").replace(/,/g, "\\,") } $(function() { $("#addcommentform").submit(function() { $(".error").hide(); var a = "<entry xmlns='http://www.w3.org/2005/Atom'><title>Comment</title>"; if ($("#authenticated").length == 0) { a += "<author>"; if ($.trim($("#txtName").val()).length == 0) { $("#nameError").fadeIn("slow"); return false } else { a += "<name>" + parse($("#txtName").val()) + "</name>" } if ($.trim($("#txtEmail").val()).length == 0 || $("#txtEmail").val().search(emailRegxp) == -1) { $("#emailError").fadeIn("slow"); return false } else { a += "<email>" + encodeURI($("#txtEmail").val()) + "</email>" } if ($.trim($("#txtWebsite").val()) != "http://" && $.trim($("#txtWebsite").val()).length > 0) { if ($("#txtWebsite").val().search(urlRegxp) == -1) { $("#websiteError").fadeIn("slow"); return false } else { a += "<uri>" + encodeURI($("#txtWebsite").val()) + "</uri>" } } a += "</author>" } if ($.trim($("#txtComment").val()).length == 0) { $("#commentError").fadeIn("slow"); return false } else { a += "<content type='html'>" + parse($("#txtComment").val()) + "</content></entry>" } $.ajax({ type: "POST", url: $("#addcommentform").attr("action"), data: a, contentType: "application/atom+xml;type=entry", dataType: "xml", complete: function(c) { if (c.status == 200) { reset(); var b = $(c.responseText); b.addClass("commentSelf").fadeTo(0, 0, function() { b.appendTo("#comments").fadeTo(1000, 1); $("abbr[class*=timeago]").timeago(); $("#commentsEmpty").remove() }) } else { alert("Failed to post comment: " + c.statusText + "\n" + c.responseText) } } }); return false }) }); function parse(a) { if (a) { return a.replace(/\n/, "<br />").replace(/&/g, "&amp;").replace(/\"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;") } return "" } function reset() { $(".commentError").hide(); $("#txtComment")[0].value = "" } var emailRegxp = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i; var urlRegxp = /^(?:https?|s?ftp|telnet|ssh|scp):\/\/(?:(?:[\w]+:)?\w+@)?(?:(?:(?:[\w-]+\.)*\w[\w-]{0,66}\.(?:[a-z]{2,6})(?:\.[a-z]{2})?)|(?:(?:25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.)(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})))(?:\:\d{1,5})?(?:\/(~[\w-_.])?)?(?:(?:\/[\w-_.]*)*)?\??(?:(?:[\w-_.]+\=[\w-_.]+&?)*)?$/i; $.fn.watermark = function(c) { var a = { color: "#999" }; var b = $.extend({}, a, c); return this.each(function() { var d = $(this); d.attr("baseColor", d.css("color")); if (!d.attr("title")) { d.attr("title", d.val()) } if (d.val() == d.attr("title")) { d.attr("isWatermark", 1); d.css("color", b.color) } d.bind("focus", function() { var e = $(this); if (e.val() != e.attr("title") && e.val() != "") { e.attr("isWatermark", 0) } if (e.attr("isWatermark") == 1) { e.val(""); e.attr("isWatermark", 0); e.css("color", e.attr("baseColor")) } }).bind("blur", function() { var e = $(this); if (e.val() != e.attr("title") && e.val() != "") { e.attr("isWatermark", 1) } if (e.attr("isWatermark") == 0) { e.css("color", b.color); if (e.val() == "") { e.attr("isWatermark", 1); e.val(e.attr("title")) } } }) }) };
$.fn.openid = function() {
    var l = $(this); 
    var h = l.find("input[name=openid_username]");
    var k = l.find("input[name=openid_identifier]"); 
    var c = l.find("div:has(input[name=openid_username])>span:eq(0)");
    var g = l.find("div:has(input[name=openid_username])>span:eq(1)"); 
    var j = l.find("fieldset:has(input[name=openid_username])");
    var b = l.find("fieldset:has(input[name=openid_identifier])");
    var i = function() { if (h.val().length < 1) { h.focus(); return false } k.val(c.text() + h.val() + g.text()); return true };
    var a = function() { if (k.val().length < 1) { k.focus(); return false } return true };

    var f = function() 
    {
        var m = $(this); 
        m.parent().find("li").removeClass("highlight");
        m.addClass("highlight"); 
        j.fadeOut();
        b.fadeOut(); 
        l.unbind("submit").submit(function() { k.val(l.find("li.highlight span").text()) });
        l.submit(); 
        return false
    };

var e = function() {
    var m = $(this); m.parent().find("li").removeClass("highlight"); m.addClass("highlight");
    j.hide(); b.show(); k.focus(); l.unbind("submit").submit(a); return false
};
var d = function() {
    var m = $(this); m.parent().find("li").removeClass("highlight"); m.addClass("highlight"); b.hide();
    j.show(); l.find("label[for=openid_username] span").text(m.attr("title")); c.text(m.find("span").text().split("username")[0]);
    g.text("").text(m.find("span").text().split("username")[1]); k.focus(); l.unbind("submit").submit(i); return false
};
l.find("li.direct").click(f);
l.find("li.openid").click(e);
l.find("li.username").click(d);
k.keypress(function(m) { if ((m.which && m.which == 13) || (m.keyCode && m.keyCode == 13)) { return a() } });
h.keypress(function(m) { if ((m.which && m.which == 13) || (m.keyCode && m.keyCode == 13)) { return i() } });
l.find("li span").hide(); l.find("li").css("line-height", 0).css("cursor", "pointer");
l.find("li:eq(0)").click(); return this
}; 
$.fn.rater = function(b) { var a = $.extend({}, $.fn.rater.defaults, b); return this.each(function() { var e = $(this); var d = e.find(".ui-rater-starsOn"); var c = e.find(".ui-rater-starsOff"); if (a.size == undefined) { a.size = c.height() } if (a.rating == undefined) { a.rating = d.width() / a.size } if (a.id == undefined) { a.id = e.attr("id") } c.mousemove(function(i) { var h = i.clientX - c.offset().left; var g = c.width() - (c.width() - h); g = Math.min(Math.ceil(g / (a.size / a.step)) * a.size / a.step, a.size * a.ratings.length); d.width(g); var f = Math.round(d.width() / c.width() * (a.ratings.length * a.step)) / a.step; e.attr("title", a.ratings[f - 1] == undefined ? f : a.ratings[f - 1]) }).hover(function(f) { d.addClass("ui-rater-starsHover") }, function(f) { d.removeClass("ui-rater-starsHover"); d.width(a.rating * a.size) }).click(function(g) { var f = Math.round(d.width() / c.width() * (a.ratings.length * a.step)) / a.step; $.fn.rater.rate(e, a, f) }).css("cursor", "pointer"); d.css("cursor", "pointer") }) }; $.fn.rater.defaults = { postHref: location.href, ratings: ["Bad", "Boring", "Average", "Good", "Great"], step: 1 }; $.fn.rater.rate = function(e, a, b) { var d = e.find(".ui-rater-starsOn"); var c = e.find(".ui-rater-starsOff"); c.fadeTo(600, 0.4, function() { $.ajax({ url: a.postHref, type: "POST", data: "id=" + a.id + "&rating=" + b, complete: function(f) { if (f.status == 200) { a.rating = parseFloat(f.responseText); c.unbind("click").unbind("mousemove").unbind("mouseenter").unbind("mouseleave"); c.css("cursor", "default"); d.css("cursor", "default"); c.fadeTo(600, 0.1, function() { d.removeClass("ui-rater-starsHover").width(a.rating * a.size); var g = e.find(".ui-rater-rateCount"); if (g) { g.text(parseInt(g.text()) + 1); e.find(".ui-rater-rating").text(a.rating.toFixed(1)) } c.fadeTo(500, 1); e.attr("title", "Your rating: " + b.toFixed(1)) }) } else { alert(f.responseText); c.fadeTo(2200, 1) } } }) }) };